package com.lichuandi;

import org.springframework.http.HttpMethod;
import org.springframework.web.client.RestTemplate;

import java.io.*;
import java.net.Socket;

public class JavaClient {
    public static void main(String[] args) {
        try {
//            RestTemplate restTemplate = new RestTemplate();
//            restTemplate.exchange("locua", HttpMethod.GET,Object.class)
            // 连接Python服务端（IP和端口需匹配）
//            Socket socket = new Socket("192.168.0.173", 12345);
            Socket socket = new Socket("localhost", 12345);
            System.out.println("已连接到Python服务端");

            // 发送数据
            OutputStream output = socket.getOutputStream();
            PrintWriter writer = new PrintWriter(output, true);
            writer.println("Hello from Java客户端!");

            // 接收响应
            InputStream input = socket.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(input));
            String response = reader.readLine();
            System.out.println("收到Python服务端响应: " + response);

            // 关闭连接
            socket.close();
        } catch (IOException e) {
            System.err.println("客户端异常: " + e.getMessage());
        }
    }
}
